var MovieRoom = {
	
	sessionId:null,
	
	selectSeats : function(img) {		
		var orderSeatNos = document.getElementById("orderSeatNos").value;
		var flag = 1;
		if(img.src.indexOf("chair_available.jpg") != -1) {		
			orderSeatNos = orderSeatNos+","+img.id;	
			img.src = "images/chair_pick.jpg";
		}
		else {	
			flag = 0;
			var imgid = img.id;
			var index = orderSeatNos.indexOf(imgid);
			orderSeatNos = orderSeatNos.substring(0,index-1) + orderSeatNos.substring(index+imgid.length,orderSeatNos.length);
			img.src = "images/chair_available.jpg";
		}
		document.getElementById("orderSeatNos").value = orderSeatNos;
		this.updateSessionSeats(img.id,flag);
		return true;
	},
	
	updateSessionSeats : function(pos,flag){		
		var mrSessionSeats = document.getElementById("sessionSeats").value;
		var posArray = pos.split("_");
		var rowIndex = posArray[0];
		var seatIndex = posArray[1];
		var changeIndex = Number(rowIndex)*16+Number(seatIndex);
		mrSessionSeats = mrSessionSeats.substring(0,changeIndex)+flag+mrSessionSeats.substring(changeIndex+1,mrSessionSeats.length);
		document.getElementById("sessionSeats").value = mrSessionSeats;
	},
	
	askForSessionInfo : function(){
		var href = "seatsSelect.do?method=getSessionInfo&sessionId="+this.sessionId;
		ajaxRequest(href, this.loadSessionInfo, null);
	},
	
	loadSessionInfo : function(ajax_request) {
		var sessionInfo = eval("(" + ajax_request.responseText + ")");
		
		document.getElementById("mrName").innerHTML = sessionInfo.sessionInfo[0].mrName;
		document.getElementById("mrLanguage").innerHTML = sessionInfo.sessionInfo[0].mrLanguage;
		document.getElementById("mrTime").innerHTML = sessionInfo.sessionInfo[0].mrTime;
		document.getElementById("mrSessionDate").innerHTML = sessionInfo.sessionInfo[0].mrSessionDate;
		document.getElementById("sessionSeats").value = sessionInfo.sessionInfo[0].mrSessionSeats;
		
		var seats = sessionInfo.sessionInfo[0].mrSessionSeats;
		var allSeatsDiv = document.getElementById("allSeats");
		var seatsArray = seats.split(",");
		for(var rowIndex = 0 ; rowIndex < seatsArray.length; rowIndex++){
			
			var rowSeat = seatsArray[rowIndex];
			
			for(var seatIndex = 0 ; seatIndex < rowSeat.length; seatIndex++){
				
				var img = document.createElement("img");
				img.setAttribute("id",rowIndex+"_"+seatIndex);
				if(rowSeat[seatIndex]==0){
					img.setAttribute("src", "images/chair_available.jpg");
					img.setAttribute("onclick","MovieRoom.selectSeats(this)");
				}
				else if(rowSeat[seatIndex]==1){
					img.setAttribute("src", "images/chair_sold.jpg");
				}			
				allSeatsDiv.appendChild(img);		
			}
			var br = document.createElement("br");
			allSeatsDiv.appendChild(br);			
		}
		
	//	dijit.byId("loadDiv").hide();
	}
		
};